# Load models
load("Data/exp_2/slopes.Rdata")
load("Data/exp_3/slopes.Rdata")

# Combine Experiment 2 slopes
exp2_slopes <- bind_rows(
    exp2_in_therm_pool_slopes,
    exp2_out_therm_pool_slopes,
    exp2_violence_pool_slopes,
    exp2_norms_pool_slopes
) %>%
    mutate(
        Study = "Experiment 2"
    ) %>%
    select(
        Study, fact_type, dv, estimate, std.error
    )

# Combine Experiment 3 slopes
exp3_slopes <- bind_rows(
    exp3_in_therm_pool_slopes,
    exp3_out_therm_pool_slopes,
    exp3_violence_pool_slopes,
    exp3_norms_pool_slopes
) %>%
    mutate(
        Study = "Experiment 3"
    ) %>%
    select(
        Study, fact_type, dv, estimate, std.error
    )

# Combine all slopes
exp_slopes <- bind_rows(exp2_slopes, exp3_slopes)

# Clean up slopes
exp_slopes <- exp_slopes %>%
    rename(
        Beta = estimate,
        SE = std.error,
        `Statistic Type` = fact_type,
        `Dependent Variable` = dv
    ) %>%
    mutate(
        `Statistic Type` = case_when(
            `Statistic Type` == "policy" ~ "Policy Preference",
            `Statistic Type` == "dem_norm" ~ "Support for Undemocratic Practice",
            `Statistic Type` == "demo" ~ "Demographic"
        ),
        `Dependent Variable` = case_when(
            `Dependent Variable` == "out_therm_post" ~ "Out-Party Warmth",
            `Dependent Variable` == "in_therm_post" ~ "In-Party Warmth",
            `Dependent Variable` == "norms_post" ~ "Support for Undemocratic Practices",
            `Dependent Variable` == "violence_post" ~ "Support for Partisan Violence"
        )
    )

# Generate table
exp_slopes %>%
    datasummary_df(
        title = "Pooled Group-Average Marginal Effects of Moving Statistic One
        Percentage Point in Direction of Party Stereotype (Experiment 2 and 3)",
        notes = "Note: Estimates come from a model with the following form:
        Post-Treatment Dependent Variable = Deviation of Statistic from
        Participant's Prior * Statistic Type * Poll Subject's Role * Poll Party
        + Participant's Prior. In Experiment 2, standard errors are clustered
        at the participant level. n$_{3}$ = 1,642; n$_{4}$ = 2,484.",
        output = "Tables/pre_reg_deviations.txt"
    )
